********************************************************************************************
********* THIS FILE EXAMINES THE DIVERGENCES BETWEEN THE MEXICAN GOVERNMENT DATA ***********
********* MEASURING FOREST AND THE HANSEN DATA IN 2010 ********************
*** DATE: 12/30/2019 *********
*** UPDATED: 8/11/21 *********
*** AUTHOR: JAG **************
*** VERSION: STATA 16 ********

clear*
grstyle init
grstyle set plain
*glo data "C:\Users\03638881\Dropbox\Satellite data measurement\Data\"
*glo outputs "C:\Users\03638881\Dropbox\Satellite data measurement\Latex\tables\"
*glo graphs "C:\Users\03638881\Dropbox\Satellite data measurement\Latex\graphs\"
use "${data}defor_frontier_panel_wLS.dta", clear
rename forest2011 forest2010
drop forestbin hansenbin
gen forestbin = forest2010 > .10
gen hansenbin = hansen2010 > .10

estpost sum forest2010 hansen2010 forestbin hansenbin elev_mean slope_mean slope_std dtropical mtropical pine mangrove dry num_scenesL72010 num_scenesL52011 minscenes
 
esttab using "${outputs}\sumstats.tex", cells("mean(fmt(3) label(Mean)) sd(fmt(3) label(SD)) count(fmt(0) label(Obs ))") ///
style(tex) label nonumbers noobs replace ///
	postfoot( \hline \hline \end{tabular}} \begin{tablenotes}[para,flushleft] \footnotesize{Table shows simple summary ///
	statistics for all variables used in analysis.  ///
	L7 indicates the Landsat 7 satellite.} \end{tablenotes} ) 


estpost tab forestbin hansenbin 
 esttab .  using "${outputs}sumstats2.tex", replace cell(pct(fmt(%5.1f))) unstack nonumber nomtitles nodepvars nonumbers ///
 label fragment collabels("" "" "" )  noobs ///
 prehead( \begin{tabular}{lccc}    \hline \hline ///
& \multicolumn{2}{c}{Hansen data} \\) ///
  posthead(\hline GOM data & \\  ) ///
  postfoot( \hline \hline \end{tabular} \begin{tablenotes}[para,flushleft] \footnotesize{Table shows cross-tabulation for two data sources used in analysis.  Cells show percentages in each category.} \end{tablenotes} )
	

	
tw scatter forest2010 hansen2010, saving(g1, replace) ms(p) mc(gs0)  ///
	ytitle("Proportion forest, 2011" "GOM Data") xtitle("Proportion forest, 2010" "Hansen Data") 
graph export "${graphs}/dm1.png", replace

tw scatter forest2010 hansen2010, ms(p) mc(gs0) || scatter  forest2010 hansen2010 if meanscenesL7>10, saving(g2, replace)	ms(x) mc(red) ///
	ms(x)  ytitle("Proportion forest, 2011" "GOM Data") xtitle("Proportion forest, 2010" "Hansen Data")  legend(lab(1 "Full Sample") ///
	lab(2 "No. Cloud Free Images Above Median") col(1) pos(5) ring(0))	
graph export "${graphs}/dm1a.png", replace

cumul forest2010, g(cdf_f)
cumul hansen2010, g(cdf_h)	
tw connected cdf_f forest2010, sort ms(i) lc(gs0) lp(dash) || ///
	connected cdf_h hansen2010, sort ms(i) lc(red) lp(longdash_dot) ///
	ytitle("Cumulative Probability") xtitle("Proportion Forest Coverage") ///
	legend(lab(1 "GOM Data") lab(2 "Hansen Data") col(1)) yline(1, lc(gs0)) 
graph export "${graphs}/dm2.png", replace
